package com.xtxk.contorller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xtxk.dto.out.LoginDto;
import com.xtxk.service.control.ControlService;
import com.xtxk.service.device.DeviceService;
import com.xtxk.service.login.LoginService;
import com.xtxk.service.notification.NotificatService;
import com.xtxk.service.seed.DirectSeedService;
import com.xtxk.utils.result.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author tiger
 *
 * 基础控制类
 */
@RestController
@Api(tags = "业务BIZ")
@RequestMapping(value = "/v1")
public class BizController {
	
	@Resource
	private DeviceService device;
	
	// 登录
	@Resource
	private LoginService service;
	
	// 通知
	@Resource
	private NotificatService notifi;
	
	// 直播
	@Resource
	private DirectSeedService seed;
	
	// 控制（云台、镜头）
	@Resource
	private ControlService control;

	public static Logger log = LoggerFactory.getLogger(BizController.class);

	@RequestMapping(value = "/adddevice", method = RequestMethod.POST)
	@ApiOperation("添加设备信息")
	public Result<?> addDevice() {
		return Result.ok(device.addDevice());
	}
	
	@RequestMapping(value = "/editdevice", method = RequestMethod.POST)
	@ApiOperation("修改设备信息")
	public Result<?> editDevice() {
		return Result.ok(device.editDevice());
	}
	
	@RequestMapping(value = "/removedevice", method = RequestMethod.POST)
	@ApiOperation("删除设备信息")
	public Result<?> removeDevice(@RequestParam("deviceID")String deviceID) {
		return Result.ok(device.removeDevice(deviceID));
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	@ApiOperation("7-登录认证操作")
	public Result<?> login(@RequestBody LoginDto dto) {
		return Result.ok(service.login());
	}

	@RequestMapping(value = "/logout", method = RequestMethod.POST)
	@ApiOperation("8-注销登录退出")
	public Result<?> logout(@RequestBody LoginDto dto) {
		return Result.ok(true);
	}
	
	@RequestMapping(value = "/onmedialinkevent", method = RequestMethod.GET)
	@ApiOperation("9-媒体连接通知")
	public Result<?> onMedialinkEvent() {
		return Result.ok(notifi.medialinkevent());
	}
	
	@RequestMapping(value = "/ondevicestatusevent", method = RequestMethod.GET)
	@ApiOperation("10-设备状态通知")
	public Result<?> onDeviceStatusEvent() {
		return Result.ok(notifi.deviceStatusEevent());
	}
	
	@RequestMapping(value = "/startplay", method = RequestMethod.POST)
	@ApiOperation("11-开启直播请求")
	public Result<?> startPlay() {
		return Result.ok(seed.startPlay());
	}
	
	@RequestMapping(value = "/onstartplayevent", method = RequestMethod.GET)
	@ApiOperation("12-直播操作反馈")
	public Result<?> onStartPlayEvent() {
		return Result.ok(seed.onStartPlayEvent());
	}
	
	@RequestMapping(value = "/stopplay", method = RequestMethod.POST)
	@ApiOperation("13-停止直播请求")
	public Result<?> stopPlay() {
		return Result.ok(seed.stopPlay());
	}
	
	@RequestMapping(value = "/onstoplayevent", method = RequestMethod.GET)
	@ApiOperation("14-停播操作反馈")
	public Result<?> onStopLayEvent() {
		return Result.ok(seed.onStopLayEvent());
	}
	
	@RequestMapping(value = "/ptzctrldirection", method = RequestMethod.POST)
	@ApiOperation("15-控制云台方位")
	public Result<?> ptzCtrlDirection() {
		return Result.ok(control.ptzCtrlDirection());
	}
	
	@RequestMapping(value = "/ptzctrlzoom", method = RequestMethod.POST)
	@ApiOperation("16-控制镜头变倍")
	public Result<?> ptzCtrlZoom() {
		return Result.ok(control.ptzCtrlZoom());
	}
	
	@RequestMapping(value = "/ptzctrlfocus", method = RequestMethod.POST)
	@ApiOperation("17-控制镜头聚焦")
	public Result<?> ptzCtrlFocus() {
		return Result.ok(control.ptzCtrlFocus());
	}
	
	@RequestMapping(value = "/ptzctrlaperture", method = RequestMethod.POST)
	@ApiOperation("18-控制镜头光圈")
	public Result<?> ptzCtrlAperture() {
		return Result.ok(control.ptzCtrlAperture());
	}
}
